/*
 * 
 *  ${model.model}Controller 创建于 ${date} 版权归作者和作者当前组织所有
 */
package ${model.packageName}.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.mmk.common.ExtJsPage;
import com.mmk.common.ExtJsPageable;
import ${model.packageName}.service.${model.model}Service;
import ${model.packageName}.model.${model.model};
import ${model.packageName}.condition.${model.model}Condition;

/**
*${model.model}Controller ： ${model.comment} 的web控制层
* ${date}
*@author ${model.author}
*@version 1.0
*/
@RestController
public class ${model.model}Controller{
	private Log log = LogFactory.getLog(this.getClass());
	
	@Resource 
	private ${model.model}Service ${model.modelL}Service;

    /**
	 * 跳转至列表页面
	 * @param ${model.modelL}Condition 查询参数
	 * @param pageable 分页参数
	 * @return 返回页面以及页面模型
	 * @author ${model.author}
     * 
	 */
	@RequestMapping("/${model.modelL}/list")
	@ResponseBody
	public ExtJsPage<${model.model}> list(${model.model}Condition ${model.modelL}Condition, ExtJsPageable pageable){		
	    log.info("${model.comment}列表查询");
		Page<${model.model}> ${model.modelL}Page =${model.modelL}Service.list(${model.modelL}Condition,pageable.pageable());		
		return  new ExtJsPage< ${model.model} >(${model.modelL}Page);
	}
	
	
	/**
	 * ${model.comment}数据保存方法
	 * @param ${model.modelL} 要保存的数据
	 * @return 保存后的数据
	 * @author ${model.author}
     * 
	 */
	@RequestMapping("/${model.modelL}/save")
	@ResponseBody
	public ${model.model} save(${model.model} ${model.modelL}){
		log.info("${model.comment}保存");
		return ${model.modelL}Service.save(${model.modelL});
	}
	
	/**
     * ${model.comment}数据批量保存方法
     * @param ${model.modelL}List 要保存的数据
     * @return 是否成功
     * @author ${model.author}
     * 
     */
    @RequestMapping("/${model.modelL}/saveAll")
    @ResponseBody
    public boolean save(@RequestBody List<${model.model}> ${model.modelL}List){
        log.info("${model.comment}批量保存");
        try {
            ${model.modelL}Service.save(${model.modelL}List);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage(),e);
            return false;
        }
    }

	
	/**
	 * 跳转至详细信息页面
	 * @param ${model.modelL} 要查询的数据
	 * @return 返回详情数据
	 * @author ${model.author}
     * 
	 */ 
	@RequestMapping("/${model.modelL}/details")
	@ResponseBody
	public ${model.model} details(${model.model} ${model.modelL}){
		log.info("${model.comment}详细信息");
		${model.modelL} = ${model.modelL}Service.find(${model.modelL}.get${pkFieldUp}());
		return ${model.modelL};
	}
	
	/**
	 * 删除数据操作组方法
	 * @param ${model.modelL} 要删除的数据
	 * @return 是否成功
	 * @author ${model.author}
     * 
	 */
	@RequestMapping("/${model.modelL}/delete")
	public boolean delete(${model.model} ${model.modelL}){
		log.info("${model.comment}删除");
        try {
            ${model.modelL}Service.delete(${model.modelL});
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return false;
        }
        return true; 
	}
	
	/**
     * 批量删除数据操作组方法
     * @param ${model.modelL}List 要删除的数据
     * @return ture or false 如果成功返回true ,出现错误返回false
     * @author ${model.author}
     * 
     */
    @RequestMapping("/${model.modelL}/deleteAll")
    public boolean delete(List<${model.model}> ${model.modelL}List){
        log.info("${model.comment}批量删除");
        try {
            ${model.modelL}Service.delete(${model.modelL}List);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return false;
        }
        return true; 
    }
	
#foreach($field in ${fieldList})
#if($field.existsMethod)
    /**
     * 跳转至详细信息页面
     * @param ${field.field} 检查的数据
     * @return  true or false
     * @author ${model.author}
     * 
     */ 
    @RequestMapping("/${model.modelL}/${field.field}/exist")
    @ResponseBody
    public boolean exists${field.fieldUp}(${field.type} ${field.field}){
        log.info("检测${model.comment}是否存在  ${field.field}");
        return ${model.modelL}Service.exists${field.fieldUp}(${field.field});
    }
#end
#end
}